package nz.ac.massey.se.Q5;


import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashSet;

/**
 * Design pattern Q5
 *
 * @author Charles Zheng
 * @id 19029962
 */

public class CarGenerator_refactored {

    private static Object engineer;
    static Object designer;
    static int year;


    private static CarGenerator_refactored carGenerator;

    public static void main(String[] args) throws Exception {
        carGenerator = new CarGenerator_refactored();
        Car car1 = carGenerator.produceCar();
        Car car2 = carGenerator.produceCar();

        HashSet<String> colorsOption1 = new HashSet<>();
        ArrayList<String> colorOption2 = new ArrayList<>();
        carGenerator.Paint(colorsOption1, colorOption2);
        carGenerator.Paint(colorsOption1, colorOption2);

    }

    //a method to produce another car. It takes no argument and return a car, and throws NullPointerException
    public Car produceCar() throws NullPointerException {
        Car car = new Car();
        car.setManufacturer("Nissan");
        ;
        car.setModel("Murano");
        car.setType("SUV");
        car.setYear(2022);
        engineer = new String("Sarah");
        car.madeBy(engineer, car.getModel(), LocalDateTime.now());
        printCarInfo(car);
        return car;
    }

    //display car info
    private void printCarInfo(Car car) {
        System.out.println("car \"" + car.getManufacturer() + " " + car.getModel() + "\" has been created");
    }

    public Boolean isNew(int year) {
        return year < 0;
    }


    //the method gets the car model from the Car class.
    public String getModel() throws RuntimeException {
        return carGenerator.getModel();
    }

    //the method sets paint colors for a new car using a set (hashset) of colors
    public void Paint(HashSet<String> colors, ArrayList<String> additionalColors) {
        Object key_designer = CarGenerator.designer;

        for (String color : colors) {
            if (isNew(CarGenerator.year))
                produceCar();
        }
    }
}
